/**
 * Created by chris on 16/9/27.
 */

angular.module('starter.service', [])
.factory('HotsFactory', function ($resource, G, $rootScope) {

    var resource = $resource(G.api, {}, {
        query:{
            method: 'get',
            timeout: 20000
        }
    })

    var data = {};

    return {

        //异步请求
        getHots: function () {
            resource.query({
                //url中的参数
                a: 'getPortalList',
                catid: 20,
                page: 2
            }, function (r) {
                // console.log(r);
                //通知controller拿数据
                data.result = r.result;
                $rootScope.$broadcast('updateHots');
            })

        },
        getHotsData: function () {
            return data.result;
        }
    }
})